package org.common.utils.net.netty.bytes;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import org.common.utils.net.netty.core.NettyDecode;
import org.common.utils.net.netty.core.NettyEncode;
import org.common.utils.net.netty.core.NettyHandler;
import org.common.utils.net.netty.core.NettyInitializer;

/**
 * 默认的Byte初始化器
 * @author zhouzhibing
 * @date 2025/11/13 15:09
 */
public class DefaultByteInitializer extends NettyInitializer {

    public DefaultByteInitializer(String name, NettyDecode decode , NettyEncode encode , NettyHandler handler) {
        super(name , encode , decode , handler);
    }

    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        ChannelPipeline pipeline = socketChannel.pipeline();
        pipeline.addLast(new LengthFieldBasedFrameDecoder(2048, Const.DATA_LENGTH_OFFSET, 4, 0, 0));
        pipeline.addLast(decode);
        pipeline.addLast(encode);
        pipeline.addLast(handler);
    }
}
